package com.ewhale.feitengguest.presenter.shop.mine

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.ArticleDetailDto
import com.ewhale.feitengguest.utils.pay.PayWeixinDto
import com.ewhale.feitengguest.view.shop.mine.ShopRechargeView
import com.ewhale.feitengguest.view.user.mine.SettingView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException
import java.math.BigDecimal
import java.util.HashMap

/**
 * 作者：SimGa
 * 日期：2020/1/6
 * 时间：15:04
 * 包名：com.ewhale.feitengguest.presenter.shop.mine
 */
class ShopRechargePresenter :IPresenter(){


    fun walletRecharge(payType:Int,amount:BigDecimal){
        mView.showProLoading()
        request(1,ApiHelper.USER_API.walletRecharge(payType,amount),null)
    }

    fun loadArticleDetails(id: Int) {
        mView.showProLoading()
        request(2, ApiHelper.USER_API.getArticleDetails(id.toLong()), null)
    }

    fun withDraw(params: HashMap<String, Any>) {
        mView.showProLoading()
        request(3,ApiHelper.USER_API.commitWithdrawal(params),null)
    }

    override fun <T : Any?> onNext(postCode: Int, result: T, data: Any?) {
        super.onNext(postCode, result, data)
        when(postCode){
            1->{
                (mView as ShopRechargeView).goToThirdPay(result as Any)
            }
            3->{
                (mView as ShopRechargeView).withSuccess()
            }
            2->{
                (mView as ShopRechargeView).showDetail(result as ArticleDetailDto)
            }
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode,e!!.code,e.displayMessage)
    }


}
